const url = {
  dev:'http://192.168.110.27:8089/huanwei',
  pro:'https://wxapi.huanweijia.cn'
}

export const BASE_URL = url.dev;

export let TOKEN = '123456';

//每次重启小程序重新获取token，防止token过期
export function setToken(token) {
  TOKEN = token;
}


//check用于处理一些特殊接口,如果报400传true否则不传或者传false
function request(type,url,param,check) {
  //处理一些特殊请求接口
  if(typeof param.requestPath != 'undefined') {
    url = url + '/' + param.requestPath;
  }
  var contentType = 'application/json;charset=UTF-8';
  if(check == true) {
    contentType = 'application/x-www-form-urlencoded';
  }
  return uni.request({
    url:BASE_URL + url,
    method:type,
    dataType:'json',
    header:{
      'token':TOKEN,
      'Content-Type':contentType
    },
    data:param
  })
}


export function get(url,param,check){
  return request('GET',url,param,check);
}

export function post(url,param,check){
  return request('POST',url,param,check);
}

export function deleteRequest(url,param,check){
  return request('DELETE',url,param,check);
}

export function putRequest(url,param,check){
  return request('PUT',url,param,check);
}

